package dcutils.rpg.characters;

// Import Java JDK Classes
import java.util.Random;

// Import DCUtils Classes
import dcutils.Range;
import dcutils.rpg.env.d2.Coords;
import dcutils.rpg.stats.Stat;
import dcutils.rpg.Vital;

/**
 * An instantiable player character class.
 * @author dca
 */
public class PlayerCharacter extends Character {
   protected Vital hp;
   protected Vital mp;
   protected Vital fp;

   protected Stat physStr;
   protected Stat physDef;
   protected Stat magStr;
   protected Stat magDef;
   protected Stat agility;
   protected Stat constitution;
   protected Stat charisma;

   public PlayerCharacter(
      String name,
      int hp, int mp, int fp,
      int physStr, int physDef, int magStr, int magDef, int agility, int constitution, int charisma
   ) throws Range.RangeException {
      super(name);

      this.hp = new Vital(hp);
      this.mp = new Vital(mp);
      this.fp = new Vital(fp);

      this.physStr      = new Stat(5, physStr,      500);
      this.physDef      = new Stat(5, physDef,      500);
      this.magStr       = new Stat(5, magStr,       500);
      this.magDef       = new Stat(5, magDef,       500);
      this.agility      = new Stat(5, agility,      500);
      this.constitution = new Stat(5, constitution, 500);
      this.charisma     = new Stat(5, charisma,     500);
   } // END constructor

   public PlayerCharacter(
      String name,
      Vital hp, Vital mp, Vital fp,
      Stat physStr, Stat physDef, Stat magStr, Stat magDef, Stat agility, Stat constitution, Stat charisma
   ) throws Range.RangeException {
      super(name);

      this.hp = hp;
      this.mp = mp;
      this.fp = fp;

      this.physStr      = physStr;
      this.physDef      = physDef;
      this.magStr       = magStr;
      this.magDef       = magDef;
      this.agility      = agility;
      this.constitution = constitution;
      this.charisma     = charisma;
   } // END constructor

   public PlayerCharacter(
      String name, Coords location,
      int hp, int mp, int fp,
      int physStr, int physDef, int magStr, int magDef, int agility, int constitution, int charisma
   ) throws Range.RangeException {
      super(name, location);

      this.hp = new Vital(hp);
      this.mp = new Vital(mp);
      this.fp = new Vital(fp);

      this.physStr      = new Stat(5, physStr,      500);
      this.physDef      = new Stat(5, physDef,      500);
      this.magStr       = new Stat(5, magStr,       500);
      this.magDef       = new Stat(5, magDef,       500);
      this.agility      = new Stat(5, agility,      500);
      this.constitution = new Stat(5, constitution, 500);
      this.charisma     = new Stat(5, charisma,     500);
   } // END constructor

   public PlayerCharacter(
      String name, Coords location,
      Vital hp, Vital mp, Vital fp,
      Stat physStr, Stat physDef, Stat magStr, Stat magDef, Stat agility, Stat constitution, Stat charisma
   ) throws Range.RangeException {
      super(name, location);

      this.hp = hp;
      this.mp = mp;
      this.fp = fp;

      this.physStr      = physStr;
      this.physDef      = physDef;
      this.magStr       = magStr;
      this.magDef       = magDef;
      this.agility      = agility;
      this.constitution = constitution;
      this.charisma     = charisma;
   } // END constructor

   public Vital hp() {
      return this.hp;
   } // END hp getter

   public Vital mp() {
      return this.mp;
   } // END mp getter

   public Vital fp() {
      return this.fp;
   } // END fp getter

   public Stat physStr() {
      return this.physStr;
   } // END physStr getter

   public Stat physDef() {
      return this.physDef;
   } // END physDef getter

   public Stat magStr() {
      return this.magStr;
   } // END magStr getter

   public Stat magDef() {
      return this.magDef;
   } // END magDef getter

   public Stat agility() {
      return this.agility;
   } // END agility getter

   public Stat constitution() {
      return this.constitution;
   } // END constitution getter

   public Stat charisma() {
      return this.charisma;
   } // END charisma getter

   @Override
   public String toString() {
      final StringBuffer buffer = new StringBuffer();

      buffer.append(super.toString());

      buffer.append(String.format("%n%s = %s", "hp", hp()));
      buffer.append(String.format("%n%s = %s", "mp", mp()));
      buffer.append(String.format("%n%s = %s", "fp", fp()));

      buffer.append(String.format("%n%-12s = %s", "phys.str",     physStr()));
      buffer.append(String.format("%n%-12s = %s", "phys.def",     physDef()));
      buffer.append(String.format("%n%-12s = %s", "mag.str",      physStr()));
      buffer.append(String.format("%n%-12s = %s", "mag.def",      physDef()));
      buffer.append(String.format("%n%-12s = %s", "agility",      agility()));
      buffer.append(String.format("%n%-12s = %s", "constitution", constitution()));
      buffer.append(String.format("%n%-12s = %s", "charisma",     charisma()));

      return buffer.toString();
   } // END toString

   public static PlayerCharacter createPlayerCharacter(String name) throws Range.RangeException {
      final Random rand = new Random();

      return new PlayerCharacter(
         name,
         (15 + rand.nextInt(15)), (15 + rand.nextInt(15)), (15 + rand.nextInt(15)),
         (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15))
      );
   } // END createPlayerCharacter

   public static PlayerCharacter createPlayerCharacter(String name, Coords location) throws Range.RangeException {
      final Random rand = new Random();

      return new PlayerCharacter(
         name, location,
         (15 + rand.nextInt(15)), (15 + rand.nextInt(15)), (15 + rand.nextInt(15)),
         (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15)), (5 + rand.nextInt(15))
      );
   } // END createPlayerCharacter
} // END class PlayerCharacter
